package com.sc.service.impl.csm;

import com.sc.dto.PatrolDailyDTO;
import com.sc.dto.PatrolMonthlyDTO;
import com.sc.dto.PatrolWeeklyDTO;
import com.sc.mapper.csm.PatrolReportMapper;
import com.sc.result.PageResult;
import com.sc.service.csm.PatrolReportService;
import com.sc.vo.PatrolDailyVO;
import com.sc.vo.PatrolMonthlyVO;
import com.sc.vo.PatrolWeeklyVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PatrolReportServiceImpl implements PatrolReportService {

    private final PatrolReportMapper baseMapper;

    @Override
    public PageResult<PatrolDailyVO> daily(PatrolDailyDTO patrolDailyDTO) {
        int start = (patrolDailyDTO.getPageNum() - 1) * patrolDailyDTO.getPageSize();
        int end = patrolDailyDTO.getPageNum() * patrolDailyDTO.getPageSize();

        List<PatrolDailyVO> patrolDailyVOList = baseMapper.daily(patrolDailyDTO);
        PageResult<PatrolDailyVO> page = new PageResult<>(patrolDailyVOList.size(), patrolDailyVOList.subList(start, Math.min(patrolDailyVOList.size(), end)));
        return page;
    }

    @Override
    public PageResult<PatrolWeeklyVO> weekly(PatrolWeeklyDTO patrolWeeklyDTO) {
        int start = (patrolWeeklyDTO.getPageNum() - 1) * patrolWeeklyDTO.getPageSize();
        int end = patrolWeeklyDTO.getPageNum() * patrolWeeklyDTO.getPageSize();

        List<PatrolWeeklyVO> patrolWeeklyVOList = baseMapper.weekly(patrolWeeklyDTO);
        PageResult<PatrolWeeklyVO> page = new PageResult<>(patrolWeeklyVOList.size(), patrolWeeklyVOList.subList(start, Math.min(patrolWeeklyVOList.size(), end)));
        return page;
    }

    @Override
    public PageResult<PatrolMonthlyVO> monthly(PatrolMonthlyDTO patrolMonthlyDTO) {
        int start = (patrolMonthlyDTO.getPageNum() - 1) * patrolMonthlyDTO.getPageSize();
        int end = patrolMonthlyDTO.getPageNum() * patrolMonthlyDTO.getPageSize();

        List<PatrolMonthlyVO> patrolMonthlyVOList = baseMapper.monthly(patrolMonthlyDTO);
        PageResult<PatrolMonthlyVO> page = new PageResult<>(patrolMonthlyVOList.size(), patrolMonthlyVOList.subList(start, Math.min(patrolMonthlyVOList.size(), end)));
        return page;
    }
}
